package com.woniuxy.user.service.Impl;

import com.hc.entity.Follow;
import com.hc.entity.NoticeArriva;
import com.hc.entity.User;
import com.woniuxy.user.dto.UserPaper;
import com.woniuxy.user.dto.UserTwo;
import com.woniuxy.user.mapper.NoticeArrivaMapper;
import com.woniuxy.user.mapper.UserMapper;
import com.woniuxy.user.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Resource
    private NoticeArrivaMapper noticeArrivaMapper;
    @Override
    public List<UserTwo> findFollowedUserByUserId(Integer uid) {
        return userMapper.findFollowedUserByUserId(uid);
    }

    @Override
    public List<UserTwo> findLetterUserByUserId(Integer uid) {
        return userMapper.findLetterUserByUserId(uid);
    }

    @Override
    public List<Follow> findCommonFriendByUserId(Integer uid) {
        List<Follow> friends = userMapper.findFriendById(uid);
        return friends;
    }

    @Override
    public User findById(Integer uid) {
        User user = userMapper.findById(uid);
        return user;
    }

    @Override
    public UserTwo findUserById(Integer id) {
        return userMapper.findUserById(id);
    }

    @Override
    public UserPaper getByUserId(Integer id) {
        return userMapper.getByUserId(id);
    }
    @Override
    public boolean addHashGoodNotice(NoticeArriva noticeArriva) {
        //查询是否已订阅，已订阅删除
        NoticeArriva noticeArriva1 = noticeArrivaMapper.selectNoticeArrivaByUserId(noticeArriva);
        if (noticeArriva1==null){
            noticeArrivaMapper.addNoticeArriva(noticeArriva);
            return true; //表示订阅成功
        }else {
            noticeArrivaMapper.deleteNoticeArrivaByUserId(noticeArriva);
            return false;//表示取消订阅成功
        }


    }

    @Override
    public List<NoticeArriva> selectGoodNoticeByGoodsId(NoticeArriva noticeArriva) {
        List<NoticeArriva> noticeArrivas = noticeArrivaMapper.selectGoodNoticeByGoodsId(noticeArriva);
        return noticeArrivas;
    }
}
